package com.sb.shiro.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.entity.GlobalConfiguration;
import com.baomidou.mybatisplus.enums.IdType;
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;

@Configuration
@MapperScan("com.sb.shiro.mapper*")
public class MybatisPlusConfig {
	
	/**
	 * mybatis-plus分页插件<br>
	 * 文档：http://mp.baomidou.com<br>
	 */
	@Bean
	public PaginationInterceptor paginationInterceptor() {
		PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
		paginationInterceptor.setDialectType("mysql");
		//paginationInterceptor.setOptimizeType(Optimize.JSQLPARSER.getOptimize());
		return paginationInterceptor;
	}
	
	@Bean
	GlobalConfiguration globalConfiguration() {
		GlobalConfiguration g = new GlobalConfiguration();
		g.setIdType( IdType.AUTO.getKey() );
		g.setDbType( "mysql" );
		g.setDbColumnUnderline( true );
		//g.setSqlInjector( logicSqlInjector() );
		//g.setLogicNotDeleteValue( "false" );// 逻辑删除全局值
		//g.setLogicDeleteValue( "true" );// 逻辑未删除全局值
		g.setMetaObjectHandler(myMetaObjectHandler());//公共字段自动填充
		return g;
	}
	
	@Bean
	MyMetaObjectHandler myMetaObjectHandler(){
		MyMetaObjectHandler myMetaObjectHandler = new MyMetaObjectHandler();
		return myMetaObjectHandler;
	}
	
}
